package com.eks.shiro.filter;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.UnauthorizedException;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.web.filter.PathMatchingFilter;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

/**
 * FormLoginFilter
 *
 * @author: chenfenghai
 * @version: 1.0
 * @date: 2021-03-17 17:09
 */
public class FormLoginFilter extends PathMatchingFilter {

    @Override
    protected boolean onPreHandle(ServletRequest request, ServletResponse response, Object mappedValue) throws Exception {
        Subject subject = SecurityUtils.getSubject();
        boolean isAuthenticated = subject.isAuthenticated();
        if (isAuthenticated) {
            return true;
        }
        throw new UnauthorizedException();
    }

}
